<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增obu发布')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-obupublish-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">发布名称：</label>
            <div class="col-sm-8">
                <input name="obuPublishName" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">厂家：</label>
            <div class="col-sm-8">
                <select name="obuPublishFactory" class="form-control m-b" onchange="func()">
                    <option value="聚利">聚利</option>
                    <option value="金溢">金溢</option>
                </select>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">发布的版本：</label>
            <div class="col-sm-8">
                <select name="obuPublishVersion" class="form-control m-b" id="ele" onchange="func2()">

                </select>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">发布时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="obuPublishTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">发布的url：</label>
            <div class="col-sm-8">
                <input name="obuPublishUrl" class="form-control" type="text" id="url"  readonly="readonly">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var prefix = ctx + "obupublish/obupublish"
    $("#form-obupublish-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-obupublish-add').serialize());
        }
    }

    $("input[name='obuPublishTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    var datas;

    function func() {
        //获取被选中的option标签
        var vs = $('select  option:selected').val();
        console.log(vs);
        $.ajax({
            type: "POST",
            url: "/third-system-service/obufile/obuupdata/factorylist",
            data: {
                obufileFactory: vs
            },
            success: function (data) {
                console.log(vs);
                var vaule = data.total;

                if (vaule > 0) {
                    datas = data.rows;

                    var optionstring = "";
                    for (var j = 0; j < datas.length; j++) {
                        console.log(datas[j].obufileVersion);
                        optionstring += "<option value=\"" + datas[j].obufileVersion + "\" >" + datas[j].obufileVersion + "</option>";
                    }

                    $("#ele").html(optionstring);
                    var datac = datas[0].obufileAddress;
                    $("#url").val(datac);
                } else {
                    alert("暂无文件选择，请先上传文件！")
                    $("#url").val("");
                    $("#ele").html("<option value=''>暂无</option>");

                }
            }
        });
    }

    function func2() {
        var index = $('#ele').prop('selectedIndex');
        console.log("选择！"+index)
        var datac = datas[index].obufileAddress;
        console.log("选择2！"+datac)
        $("#url").val(datac);
    }

    $(function(){
        func();
    });
</script>
</body>
</html>